#include <termios.h>
#include <signal.h>
#include <cstdio>
#include <dataIO.h>
#include <pthread.h>
#include <ringBuffer.h>
#include <stddef.h>

class SerialConnection : public DataInput, public DataOutput {
private:
	pthread_t inputThread;
	pthread_t outputThread;
public:
	pthread_mutex_t* mutex;
	bool run;
	int fd;
	RingBuffer inBuffer;
	RingBuffer outBuffer;

	SerialConnection(pthread_mutex_t* mutex);
	void init(char* name, speed_t baudRate);
	void start();
	void stop();

	char read();
	bool tryWrite(char data);
	//void write(char data);

	size_t available();
	size_t freeSpace();

	void clear();

	// virtual ~SerialConnection();
};
